package com.limeng.datastruts.queue;

public class LinkedQueue {

    private Node head;
    private Node tail;

    public static void main(String[] args) {
        LinkedQueue queue = new LinkedQueue();
        queue.push(4);
        queue.push(5);
        queue.push(1);
        queue.push(6);

        System.out.println(queue.pop());
        System.out.println(queue.pop());
        System.out.println(queue.pop());
        System.out.println(queue.pop());
    }

    public LinkedQueue() {
    }

    public boolean push(int num){
        Node node = new Node(num);
        if(head == null){
            head = node;
            tail = node;
        }else {
            tail.next = node;
            tail = node;
        }
        return true;
    }

    public int pop(){
        if(head==null) return 0;
        Node h = head;
        head = h.next;
        h.next = null;
        return h.data;
    }

    class Node{
        private int data;
        private Node next;

        public Node() {
        }

        public Node(int data) {
            this.data = data;
        }
    }
}
